package com.damie.controller;


import com.dadie.Domain.ShopOrderProductDomain;
import com.dadie.Domain.ShopShelvesDomain;
import com.dadie.Dto.ShopDto;
import com.dadie.Dto.ShopShelvesDto;
import com.dadie.parame.ShopParame;
import com.dadie.parame.ShopShelvesParame;
import com.damie.common.commonutils.R;
import com.damie.service.ShopOrderProductService;
import com.damie.service.ShopShelvesService;
import com.damie.uilt.Copy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alon
 * @since 2021-01-23
 */
@Api(value="商城controller",tags={"后台:商品上下架管理"})
@RestController
@CrossOrigin("*")
@RequestMapping("/damie/shop-shelves")
public class ShopShelvesController {
    @Resource
    private ShopShelvesService shopShelvesService;

    @PostMapping("addProductShelves")
    @ApiOperation("新增上架商品")
    public R addProductShelves(@RequestBody ShopShelvesParame shopShelvesParame){
        ShopDto shopDto = shopShelvesService.addProductShelves(shopShelvesParame);
        return R.ok().data("shop",shopDto);
    }

    @PostMapping("selectAllProductShelves")
    @ApiOperation("查看所有上架商品")
    public R selectAllProductShelves(){
        List<ShopShelvesDomain> list = shopShelvesService.list();
        List<ShopShelvesDto> collect = list.stream().map(l -> {
            return (ShopShelvesDto) Copy.copy(l, new ShopShelvesDto());
        }).collect(Collectors.toList());
        return R.ok().data("shop",collect);
    }


    @GetMapping("downProductShelves")
    @ApiOperation("下架商品")
    public R downProductShelves(String id){
        ShopDto shopDto = shopShelvesService.downProductShelves(id);
        return R.ok().data("shop",shopDto);
    }
}

